package hibernate;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

import entities.*;


public class HibernateUtil
{
	private static final SessionFactory sessionFactory;
    static
    {
    	try
        {
    		AnnotationConfiguration config = new AnnotationConfiguration();
    		config.addAnnotatedClass(ClienteEntity.class);
    		config.addAnnotatedClass(CotizacionEntity.class);
    		config.addAnnotatedClass(DireccionEntity.class);
    		config.addAnnotatedClass(FacturaEntity.class);
    		config.addAnnotatedClass(ItemCotizacionEntity.class);
    		config.addAnnotatedClass(ListaPreciosEntity.class);
    		config.addAnnotatedClass(OficinaVentaEntity.class);
    		config.addAnnotatedClass(OrdenCompraEntity.class);
    		config.addAnnotatedClass(PedidoVentaEntity.class);
    		config.addAnnotatedClass(ProveedorEntity.class);
    		config.addAnnotatedClass(RemitoEntity.class);
    		config.addAnnotatedClass(RodamientoEntity.class);
    		config.addAnnotatedClass(SolicitudCompraEntity.class);
    		config.addAnnotatedClass(UsuarioEntity.class);
    		
			sessionFactory = config.buildSessionFactory();
        }
        catch (Throwable ex)
        {
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
 
    public static SessionFactory getSessionFactory()
    {
        return sessionFactory;
    }
}
